"""
模型配置数据模式
"""

from typing import Optional, Dict, Any
from datetime import datetime
from pydantic import BaseModel


class ModelConfigBase(BaseModel):
    """模型配置基础模式"""
    name: str
    provider: str
    model_name: str
    api_key: Optional[str] = None
    base_url: Optional[str] = None
    api_version: Optional[str] = None
    temperature: str = "0.7"
    max_tokens: int = 2000
    top_p: str = "1.0"
    frequency_penalty: str = "0.0"
    presence_penalty: str = "0.0"
    timeout: int = 30
    max_retries: int = 3
    description: Optional[str] = None
    extra_config: Optional[Dict[str, Any]] = None


class ModelConfigCreate(ModelConfigBase):
    """创建模型配置模式"""
    pass


class ModelConfigUpdate(BaseModel):
    """更新模型配置模式"""
    name: Optional[str] = None
    provider: Optional[str] = None
    model_name: Optional[str] = None
    api_key: Optional[str] = None
    base_url: Optional[str] = None
    api_version: Optional[str] = None
    temperature: Optional[str] = None
    max_tokens: Optional[int] = None
    top_p: Optional[str] = None
    frequency_penalty: Optional[str] = None
    presence_penalty: Optional[str] = None
    timeout: Optional[int] = None
    max_retries: Optional[int] = None
    is_active: Optional[bool] = None
    is_default: Optional[bool] = None
    description: Optional[str] = None
    extra_config: Optional[Dict[str, Any]] = None


class ModelConfigResponse(ModelConfigBase):
    """模型配置响应模式"""
    id: int
    is_active: bool
    is_default: bool
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True


class ModelTestRequest(BaseModel):
    """模型测试请求模式"""
    model_config_id: int


class ModelTestResponse(BaseModel):
    """模型测试响应模式"""
    success: bool
    message: str
    response_time: Optional[float] = None
    response: Optional[str] = None


class ModelConfigSimpleResponse(BaseModel):
    """简化的模型配置响应模式（用于用户设置等场景，不包含默认标记）"""
    id: int
    name: str
    provider: str
    model_name: str
    is_active: bool
    description: Optional[str] = None
    created_at: datetime
    updated_at: datetime
    
    class Config:
        from_attributes = True